package com.turing.post.report.util;

import java.io.Serializable;
import java.math.BigInteger;
import java.util.Date;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.Id;
import javax.persistence.IdClass;
import javax.persistence.Table;

import com.turing.post.util.PCPSUtil;

/**
 * 发卡商机构未售卡库存日结表
 * 
 * @author ys
 * @date 2012-12-17
 */
@SuppressWarnings("serial")
@Entity
@Table(name = "IssueCardStockDaySettlement")
@IdClass(IssueCardStockDaySettlement.class)
public class IssueCardStockDaySettlement implements Serializable {

	public IssueCardStockDaySettlement() {
		super();
	}

	/**
	 * 发卡商机构
	 */
	private String issueBranchNo;
	/**
	 * 结算日期
	 */
	private Date tranDate;
	/**
	 * 卡面ID
	 */
	private BigInteger cardFaceId;
	/**
	 * 上日结余
	 */
	private BigInteger lastBalance;
	/**
	 * 制卡入库
	 */
	private BigInteger initialIn;
	/**
	 * 调拨入库
	 */
	private BigInteger transferIn;
	/**
	 * 盘盈入库
	 */
	private BigInteger surplusIn;
	/**
	 * 调拨出库
	 */
	private BigInteger transferOut;
	/**
	 * 丢失损坏出库
	 */
	private BigInteger lossDamageOut;
	/**
	 * 本日结余
	 */
	private BigInteger balance;

	@Id
	@Column(name = "ISSUEBRANCHNO", nullable = false)
	public String getIssueBranchNo() {
		return this.issueBranchNo;
	}

	public void setIssueBranchNo(String issueBranchNo) {
		this.issueBranchNo = issueBranchNo;
	}

	@Id
	@Column(name = "TRANDATE", nullable = false)
	public Date getTranDate() {
		return this.tranDate;
	}

	public void setTranDate(Date tranDate) {
		this.tranDate = tranDate;
	}

	@Id
	@Column(name = "CARDFACEID", nullable = false)
	public BigInteger getCardFaceId() {
		return this.cardFaceId;
	}

	public void setCardFaceId(BigInteger cardFaceId) {
		this.cardFaceId = cardFaceId;
	}

	@Column(name = "LASTBALANCE", nullable = false)
	public BigInteger getLastBalance() {
		return this.lastBalance;
	}

	public void setLastBalance(BigInteger lastBalance) {
		this.lastBalance = lastBalance;
	}

	@Column(name = "INITIALIN", nullable = false)
	public BigInteger getInitialIn() {
		return this.initialIn;
	}

	public void setInitialIn(BigInteger initialIn) {
		this.initialIn = initialIn;
	}

	@Column(name = "TRANSFERIN", nullable = false)
	public BigInteger getTransferIn() {
		return this.transferIn;
	}

	public void setTransferIn(BigInteger transferIn) {
		this.transferIn = transferIn;
	}

	@Column(name = "SURPLUSIN", nullable = false)
	public BigInteger getSurplusIn() {
		return this.surplusIn;
	}

	public void setSurplusIn(BigInteger surplusIn) {
		this.surplusIn = surplusIn;
	}

	@Column(name = "TRANSFEROUT", nullable = false)
	public BigInteger getTransferOut() {
		return this.transferOut;
	}

	public void setTransferOut(BigInteger transferOut) {
		this.transferOut = transferOut;
	}

	@Column(name = "LOSSDAMAGEOUT", nullable = false)
	public BigInteger getLossDamageOut() {
		return this.lossDamageOut;
	}

	public void setLossDamageOut(BigInteger lossDamageOut) {
		this.lossDamageOut = lossDamageOut;
	}

	@Column(name = "BALANCE", nullable = false)
	public BigInteger getBalance() {
		return this.balance;
	}

	public void setBalance(BigInteger balance) {
		this.balance = balance;
	}

	/**
	 * 重新计算本日余额
	 */
	public void reCalcBalance() {
		BigInteger bal = getLastBalance();
		bal = bal.add(getInitialIn());
		bal = bal.add(getTransferIn());
		bal = bal.add(getSurplusIn());
		bal = bal.subtract(getTransferOut());
		bal = bal.subtract(getLossDamageOut());
		setBalance(bal);
	}

	@Override
	public int hashCode() {
		return PCPSUtil.getObjectListHashCode(new Object[] {
				getIssueBranchNo(), getTranDate(), getCardFaceId() });
	}

	@Override
	public boolean equals(Object obj) {
		if ((this == obj))
			return true;
		if ((obj == null))
			return false;
		if (!(obj instanceof IssueCardStockDaySettlement))
			return false;
		IssueCardStockDaySettlement other = (IssueCardStockDaySettlement) obj;

		if (!PCPSUtil.compareObject(this.getIssueBranchNo(), other
				.getIssueBranchNo()))
			return false;

		if (!PCPSUtil.compareObject(this.getTranDate(), other.getTranDate()))
			return false;

		return PCPSUtil.compareObject(this.getCardFaceId(), other
				.getCardFaceId());
	}
}
